package code1;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/17 8:26
 *
 * 修改循环不变量的二分搜索
 */
public class BinarySearch_changeloopvar {


    //    arr[left,right)范围中
    private static <E extends Comparable<E>> int search(E[] data,  E target) {

        int left = 0;
        int right = data.length;

        while (left < right){
            int mid = left +  (right - left)/2;

            if(data[mid].compareTo(target) == 0){
                return mid;
            }else  if(data[mid].compareTo(target) < 0){
                left=mid+1;
            }else{
                right = mid;
            }
        }
        return -1;


    }


}
